package org.bot.server.init;

import org.bot.client.driver.api.server.ServerUpdateClientStatus;
import org.bot.server.flow.mapper.BotFlowMapper;
import org.bot.server.job.FlowQuartzJob;
import org.bot.server.utils.Mode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @author 沧月
 * @create 0002 2023/11/2 18:07
 * @description <本地启动模式初始化所有自动任务>
 */
@Component
public class LocationFlowTaskJobCommandLineRunner implements CommandLineRunner {

    @Value("${bot.mode}")
    private String mode;

    @Autowired
    BotFlowMapper botFlowMapper;

    @Autowired
    FlowQuartzJob quartzJob;

    @Override
    public void run(String... args) throws Exception {
        String mode = Mode.LOCATION.getMode();
        if (!mode.equals(this.mode)) {
            return;
        }

        //初始化所有自动任务
        List<Map<String, Object>> list = botFlowMapper.getAllAutoTask();
        list.forEach(map -> {
            quartzJob.addFlowJob(map.get("id").toString());
        });
    }
}
